import dictPageApi from '@/api/dict/dictPageApi'
import OptionProps from '@/model/other/OptionProps'
import { useEffect, useState } from 'react'

// 获取某个字典项列表
export default function useEffectDictPage(noLoading: boolean, dictKey: string) {
  const [dictList, setDictList] = useState<OptionProps[]>([])

  useEffect(() => {
    if (!noLoading) {
      dictPageApi({
        pageSize: -1,
        dictKey,
        type: 2, // 类型：1 字典 2 字典项
        defaultOrderFlag: true,
        orderList: [{ name: 'orderNo', value: 'descend' }],
      }).then(({ data }) => {
        setDictList(
          data.data.records.map((item) => ({
            label: item.name,
            value: item.value,
          })) as OptionProps[]
        )
      })
    }
  }, [noLoading])

  return { dictList }
}
